package com.shudes.eval;

import java.util.*;

import com.shudes.game.*;

public class EquityCalculator {

	protected EquityResult equityResult; 
	
	public EquityCalculator() {
		equityResult = new EquityResult(); 
	}
	
	public EquityCalculator(EquityInput input) {
		equityResult = new EquityResult(input); 
	}
		
	public EquityResult calculate() {
		// create the set of all possible boards
		// iterate through each and see who has the best hand
		Deck deck; 
		Set<Set<Card>> cards;
		Combinatorial<Card>combin;
		Set<Card> s;		
		int size; 
		
		deck = makeDeck(); 
		
		size = 5-equityResult.getBoard().getCards().size();
		
		combin = new Combinatorial<Card>(deck.getCards());
		cards = combin.generate(size);
		for(Set<Card> trial : cards) { 
			s = new HashSet<Card>();
			s.addAll(equityResult.getBoard().getCards()); 
			s.addAll(trial);		
			
			addEquityResult(new Board(s));
		}
		
		return equityResult; 
	}
	
	protected void addEquityResult(Board b) { 
		equityResult.addObservation(new EquityObservationCalculator(equityResult).calculate(b));
	}
	
	protected Deck makeDeck() { 
		Deck deck; 
		
		deck = new Deck(); 
		
		deck.remove(equityResult.getHero());
		deck.remove(equityResult.getBoard());
		
		if(equityResult.getDeadCards()!=null) { 
			for(Card c : equityResult.getDeadCards()) { 
				deck.remove(c); 
			}
		}
		
		if(equityResult.getVillians()!=null) { 
			for(HoleCards hc : equityResult.getVillians()) {
				deck.remove(hc); 
			}
		}

		return deck;
	}

}
